import openai
import tiktoken
import tempfile
import IPython
import structlog
from gtts import gTTS
import requests
import concurrent.futures
logger = structlog.getLogger()
openai.api_key_path = '/home/jong/.openai_key'class ElevenLabsTTS:
WOMAN = 'EXAVITQu4vr4xnSDxMaL'
MAN = 'VR6AewLTigWG4xSOukaG'
BRIT_WOMAN = 'jnBYJClnH7m3ddnEXkeh'
def __init__(self, api_key_fpath='/home/jong/.elevenlabs_apikey', voice_id=None):
with open(api_key_fpath) as f:
self.api_key = f.read().strip()
self._voice_id = voice_id or self.WOMAN
self.uri = "https://api.elevenlabs.io/v1/text-to-speech/" + self._voice_id
def tts(self, text):
headers = {
"accept": "audio/mpeg",
"xi-api-key": self.api_key,
}
payload = {
"text": text,
}
return requests.post(self.uri, headers=headers, json=payload).contentclass Chat:
def __init__(self, topic, podcast="award winning NPR", max_length=4096//4, hosts=['Tom', 'Jen'], host_voices=[ElevenLabsTTS.MAN, ElevenLabsTTS.WOMAN]):
system = f"You are an {podcast} podcast with hosts {hosts[0]} and {hosts[1]}."
self._system = system
self._topic = topic
self._max_length = max_length
self._hosts = hosts
self._history = [
{"role": "system", "content": self._system},
{"role": "user", "content": f"Generate a podcast episode about {topic}, including history and other fun facts. Reference published scientific journals."},
]
self._tts_h1 = ElevenLabsTTS(voice_id=host_voices[0])
self._tts_h2 = ElevenLabsTTS(voice_id=host_voices[1])
@classmethod
def num_tokens_from_messages(cls, messages, model="gpt-3.5-turbo"):
"""Returns the number of tokens used by a list of messages."""
encoding = tiktoken.encoding_for_model(model)
num_tokens = 0
for message in messages:
num_tokens += 4 # every message follows <im_start>{role/name}\n{content}<im_end>\n
for key, value in message.items():
num_tokens += len(encoding.encode(value))
if key == "name": # if there's a name, the role is omitted
num_tokens += -1 # role is always required and always 1 token
num_tokens += 2 # every reply is primed with <im_start>assistant
return num_tokens
def message(self, next_msg=None):
# TODO: Optimize this if slow through easy caching
while len(self._history) > 1 and self.num_tokens_from_messages(self._history) > self._max_length:
logger.info(f'Popping message: {self._history.pop(1)}')
if next_msg is not None:
self._history.append({"role": "user", "content": next_msg})
logger.info('requesting openai...')
resp = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=self._history,
)
logger.info('received openai...')
text = resp.choices[0].message.content
self._history.append({"role": "assistant", "content": text})
return text
def text2speech(self, text, spacing_ms=350):
tmpdir = '/tmp'
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as thread_pool:
i = 0
jobs = []
def write_audio(msg, i, voice, **kwargs):
logger.info(f'requesting tts {i=}')
s = voice.tts(msg)
logger.info(f'received tts {i=}')
return s
text = text.replace('\n', '!!!LINEBREAK!!!').replace('\\', '')
# Build text one at a time
currline, currname = "", self._hosts[0]
name2tld = {self._hosts[0]: 'co.uk', self._hosts[1]: 'com'}
name2voice = {self._hosts[0]: self._tts_h1, self._hosts[1]: self._tts_h2}
audios = []
for line in text.split("!!!LINEBREAK!!!"):
if not line.strip(): continue
if line.startswith(f"{self._hosts[0]}: ") or line.startswith(f"{self._hosts[1]}: "):
if currline:
jobs.append(thread_pool.submit(write_audio, currline, i, name2voice[currname], lang='en', tld=name2tld[currname]))
i += 1
currline = line[4:]
currname = line[:3]
else:
currline += line
if currline:
jobs.append(thread_pool.submit(write_audio, currline, i, name2voice[currname], lang='en', tld=name2tld[currname]))
i+=1
# Concat files
audios = [b''] * len(jobs)
for future in concurrent.futures.as_completed(jobs):
idx = jobs.index(future)
audios[idx] = future.result()
logger.info('concatting audio')
audio = b''.join(audios)
logger.info('done with audio!')
display(IPython.display.Audio(audio, autoplay=True))
def step(self, msg=None):
msg = self.message(msg)
self.text2speech(msg)
return msgchat = Chat('baby penguins', podcast='CNN podcast')
chat.step()2023-03-04 18:55:02 [info ] requesting openai...
2023-03-04 18:55:17 [info ] received openai...
2023-03-04 18:55:18 [info ] requesting tts i=0
2023-03-04 18:55:18 [info ] requesting tts i=1
2023-03-04 18:55:18 [info ] requesting tts i=2
2023-03-04 18:55:18 [info ] requesting tts i=3
2023-03-04 18:55:18 [info ] requesting tts i=4
2023-03-04 18:55:18 [info ] requesting tts i=5
2023-03-04 18:55:18 [info ] requesting tts i=6
2023-03-04 18:55:18 [info ] requesting tts i=7
2023-03-04 18:55:18 [info ] requesting tts i=8
2023-03-04 18:55:18 [info ] requesting tts i=9
2023-03-04 18:55:18 [info ] received tts i=8
2023-03-04 18:55:18 [info ] requesting tts i=10
2023-03-04 18:55:19 [info ] received tts i=6
2023-03-04 18:55:19 [info ] requesting tts i=11
2023-03-04 18:55:19 [info ] received tts i=0
2023-03-04 18:55:19 [info ] requesting tts i=12
2023-03-04 18:55:19 [info ] received tts i=2
2023-03-04 18:55:19 [info ] requesting tts i=13
2023-03-04 18:55:19 [info ] received tts i=7
2023-03-04 18:55:19 [info ] requesting tts i=14
2023-03-04 18:55:19 [info ] received tts i=1
2023-03-04 18:55:19 [info ] requesting tts i=15
2023-03-04 18:55:20 [info ] received tts i=9
2023-03-04 18:55:20 [info ] requesting tts i=16
2023-03-04 18:55:20 [info ] received tts i=3
2023-03-04 18:55:20 [info ] requesting tts i=17
2023-03-04 18:55:20 [info ] received tts i=4
2023-03-04 18:55:20 [info ] requesting tts i=18
2023-03-04 18:55:20 [info ] received tts i=10
2023-03-04 18:55:20 [info ] received tts i=12
2023-03-04 18:55:21 [info ] received tts i=13
2023-03-04 18:55:21 [info ] received tts i=5
2023-03-04 18:55:21 [info ] received tts i=18
2023-03-04 18:55:21 [info ] received tts i=15
2023-03-04 18:55:22 [info ] received tts i=16
2023-03-04 18:55:22 [info ] received tts i=14
2023-03-04 18:55:24 [info ] received tts i=11
2023-03-04 18:55:43 [info ] received tts i=17
2023-03-04 18:55:43 [info ] concatting audio
2023-03-04 18:55:43 [info ] done with audio!
"Tom: Hello and welcome to the CNN podcast, I'm Tom and I'm here with Jen. \n\nJen: Hi Tom! On today's episode, we'll be talking about one of the most adorable creatures on the planet: Baby Penguins!\n\nTom: Yes, baby penguins are definitely cute, but did you know they also have a fascinating history? \n\nJen: Oh absolutely, Tom! Scientists believe that penguins evolved from flying birds over 60 million years ago during the Paleogene era.\n\nTom: Yes! Meanwhile, the oldest fossils of penguins that have been discovered date back to around 62 million years ago.\n\nJen: That's right, Tom! And did you know that not all penguins live in icy waters? According to a study published in the journal Biology Letters, researchers found the oldest known penguin fossils in New Zealand. \n\nTom: Wow, that's a really huge discovery! \n\nJen: Absolutely! Apart from their history, baby penguins have some really interesting facts about them.\n\nTom: Do you have one for us, Jen?\n\nJen: Yes! Did you know that baby penguins are born without any feathers?\n\nTom: Really? I didn't know that!\n\nJen: Yeah, baby penguins are born with a layer of down feathers, which they molt and replace with waterproof feathers over time. And here's another one, according to a study in the journal Frontiers in Zoology, baby penguins huddle together to survive in extreme temperatures. By huddling together, they can protect themselves from the harsh cold.\n\nTom: That's really amazing! I've seen photos of these huddles and they just look so adorable!\n\nJen: Absolutely! But despite all of these adorable facts, baby penguins are facing a lot of challenges in the wild.\n\nTom: That's right, Jen. One study published in the journal Proceedings of the National Academy of Sciences found that warming temperatures are shrinking their food supply, putting their survival at risk.\n\nJen: Wow, that's really concerning. But there are organizations that are working to protect penguin habitats and their food sources.\n\nTom: Yes, the World Wildlife Fund is working to protect penguin habitats by promoting sustainable fishing practices and reducing greenhouse gas emissions.\n\nJen: That's really good to hear! So, that's it for today's episode of the CNN podcast. Thanks for tuning in and we hope you learned something new about baby penguins. \n\nTom: Tune in next time for more interesting topics and discussions."
chat.step('Episode on history of Thailand, including politics and culture.')2023-03-04 13:25:38 [info ] requesting openai...
2023-03-04 13:25:51 [info ] received openai...
2023-03-04 13:25:51 [info ] requesting tts i=0 tmpdir='/tmp'
2023-03-04 13:25:54 [info ] received tts i=0
2023-03-04 13:25:54 [info ] requesting tts i=1 tmpdir='/tmp'
2023-03-04 13:25:58 [info ] received tts i=1
2023-03-04 13:25:58 [info ] requesting tts i=2 tmpdir='/tmp'
2023-03-04 13:26:03 [info ] received tts i=2
2023-03-04 13:26:03 [info ] requesting tts i=3 tmpdir='/tmp'
2023-03-04 13:26:06 [info ] received tts i=3
2023-03-04 13:26:06 [info ] requesting tts i=4 tmpdir='/tmp'
2023-03-04 13:26:09 [info ] received tts i=4
2023-03-04 13:26:09 [info ] requesting tts i=5 tmpdir='/tmp'
2023-03-04 13:26:12 [info ] received tts i=5
2023-03-04 13:26:12 [info ] requesting tts i=6 tmpdir='/tmp'
2023-03-04 13:26:16 [info ] received tts i=6
2023-03-04 13:26:16 [info ] requesting tts i=7 tmpdir='/tmp'
2023-03-04 13:26:19 [info ] received tts i=7
2023-03-04 13:26:19 [info ] requesting tts i=8 tmpdir='/tmp'
2023-03-04 13:26:32 [info ] received tts i=8
2023-03-04 13:26:32 [info ] requesting tts i=9 tmpdir='/tmp'
2023-03-04 13:26:35 [info ] received tts i=9
2023-03-04 13:26:35 [info ] requesting tts i=10 tmpdir='/tmp'
2023-03-04 13:26:46 [info ] received tts i=10
2023-03-04 13:26:46 [info ] concatting audio
2023-03-04 13:26:46 [info ] done with audio!
"Tom: Welcome to another episode of the CNN podcast! Today, we will be discussing the captivating history of Thailand, a country with a rich cultural heritage and complex political history.\n\nJen: Thailand, also known as the Kingdom of Thailand, has a history that dates back to prehistoric times. Initially, Thailand was divided into multiple city-states, and it was known as the Kingdom of Sukhothai until the 14th century.\n\nTom: The country's current royal family has a lineage that can be traced back to the 13th century. Rama I, the first king of the Chakri dynasty, ascended the throne in 1782 and is credited with establishing Bangkok as the capital of Thailand. The dynasty has been ruling the country ever since and is the world's longest-running dynasty.\n\nJen: Until the 20th century, Thailand was one of the few countries in Southeast Asia that was not colonized by Western powers. However, during World War II, the Japanese occupied the country until the end of the war in 1945.\n\nTom: The political history of Thailand has been tumultuous, with frequent coups and political instability. The military has played a dominant role in the country's politics since the 20th century.\n\nJen: Following a coup in 2014, the country was governed by a military junta until 2019. In 2019, the first general election was held after the coup, and the current prime minister is Prayut Chan-o-cha.\n\nTom: Despite a turbulent political history, Thailand has a rich and diverse culture that has attracted millions of tourists every year. From intricate temples to delicious cuisine and vibrant festivals, Thailand's culture is truly unique.\n\nJen: Traditional Thai dance and music are also a significant part of the country's cultural heritage. The Khon, a dance-drama that tells stories from the Hindu epic, Ramayana, is a popular form of traditional Thai theater.\n\nTom: One of the most well-known attractions in Thailand is the ancient city of Ayutthaya, which was the capital of the Kingdom of Sukhothai. The city is a UNESCO World Heritage Site and an excellent example of early Siamese architecture.\n\nJen: Thailand is also famous for its beaches and islands, with Phuket, Koh Samui, and Krabi being some of the most popular destinations. The country's natural beauty and warm hospitality attract millions of tourists every year.\n\nTom: That's all for today's episode. We hope you enjoyed our discussion on the history, politics, and culture of Thailand. Thanks for listening to the CNN podcast."
"""
TODO:
- runtime voice choosing to include accented voices
"""'\nTODO:\n'
chat.step('Episode on Vermont, including an interview with a former governor.')'"Welcome to our NPR podcast, where Tom and I explore the diverse culture and history of the US. In today\'s episode, we\'ll be delving deep into the picturesque state of Vermont. Known for maple syrup, fall foliage, and quaint villages, Vermont has a rich history and interesting political background." \n\nTom chimes in, "And we\'re lucky enough to have a special guest with us today, former Governor Peter Shumlin, who\'ll give us some insight into what it was like to lead this unique state. Governor Shumlin, welcome to the show!"\n\n"Thanks for having me," says Governor Shumlin. \n\n"So, Governor Shumlin, can you tell us a bit about what makes Vermont so special?" Jen asks. \n\n"Well, I think what makes Vermont so special is its sense of community. Over the years, Vermonters have come together to support one another in times of need, from disaster relief to economic challenges. This support is what makes Vermont such a great place to live and work," Governor Shumlin replies. \n\nJen adds, "And I understand that Vermont was the first state to introduce civil unions for same-sex couples. Can you tell us a bit about that?" \n\n"Yes, that\'s correct. In 2000, Vermont became the first state to legalize civil unions for same-sex couples. It was a hard-fought battle, but in the end, Vermont showed that it was possible to recognize the equal rights of all individuals," Governor Shumlin explains. \n\nTom jumps in, "That\'s really interesting. Vermont seems to set itself apart when it comes to taking progressive steps. How did Vermont\'s political history shape this forward-thinking mentality?" \n\n"Good question. Vermont has a long-standing tradition of including its citizens in decision-making. From town-hall meetings to its unique legislature, Vermonters are encouraged to voice their opinions and participate in their democracy. This tradition has translated into a mindset of progressiveness, where we\'re always looking for new and innovative ways to make life better for our citizens," Governor Shumlin says. \n\nJen concludes, "Thanks for your insight, Governor Shumlin. Vermont certainly has an interesting mix of modern progressiveness and traditional community values. Join us next time as we explore another unique state here on our NPR podcast."'
cnn_chat = Chat('penguin social hierarchy', podcast='CNN')
cnn_chat.step()2023-03-04 11:42:09 [info ] requesting openai...
2023-03-04 11:42:24 [info ] received openai...
2023-03-04 11:42:24 [info ] requesting tts i=0
2023-03-04 11:42:24 [info ] received tts i=0
2023-03-04 11:42:25 [info ] requesting tts i=1
2023-03-04 11:42:25 [info ] received tts i=1
2023-03-04 11:42:26 [info ] requesting tts i=2
2023-03-04 11:42:26 [info ] received tts i=2
2023-03-04 11:42:27 [info ] requesting tts i=3
2023-03-04 11:42:27 [info ] received tts i=3
2023-03-04 11:42:30 [info ] requesting tts i=4
2023-03-04 11:42:30 [info ] received tts i=4
2023-03-04 11:42:32 [info ] requesting tts i=5
2023-03-04 11:42:32 [info ] received tts i=5
2023-03-04 11:42:33 [info ] requesting tts i=6
2023-03-04 11:42:33 [info ] received tts i=6
2023-03-04 11:42:37 [info ] requesting tts i=7
2023-03-04 11:42:37 [info ] received tts i=7
2023-03-04 11:42:38 [info ] requesting tts i=8
2023-03-04 11:42:38 [info ] received tts i=8
2023-03-04 11:42:39 [info ] requesting tts i=9
2023-03-04 11:42:39 [info ] received tts i=9
2023-03-04 11:42:41 [info ] requesting tts i=10
2023-03-04 11:42:41 [info ] received tts i=10
2023-03-04 11:42:43 [info ] requesting tts i=11
2023-03-04 11:42:43 [info ] received tts i=11
2023-03-04 11:42:44 [info ] requesting tts i=12
2023-03-04 11:42:44 [info ] received tts i=12
2023-03-04 11:42:46 [info ] requesting tts i=13
2023-03-04 11:42:46 [info ] received tts i=13
2023-03-04 11:42:47 [info ] concatting audio
2023-03-04 11:42:50 [info ] done with audio!
'Tom: Welcome to the CNN Podcast, I\'m Tom and I\'m joined by Jen. Today we\'ll be discussing penguin social hierarchy, their history and other fun facts.\n\nJen: Yes, penguins are fascinating creatures and we can learn a lot about their behavior and social structure by observing their interactions in the wild.\n\nTom: That\'s right, Jen. Studies have shown that penguins have a highly structured social hierarchy, with each individual penguin occupying a specific place within the group.\n\nJen: This social hierarchy is usually determined by a combination of factors, including age, strength, size, and overall health. The strongest and fittest penguins usually occupy the highest positions in the hierarchy, while the weaker and older penguins often rank lower.\n\nTom: Researchers have also found that penguins will often form groups or cliques within their social structures, with some penguins forming bonds with others in the same rank, while others may try to climb the ranks by forming alliances with higher-ranked penguins.\n\nJen: Interestingly, the social dynamics of penguins have been studied for over a century, with the first research on penguin behavior being conducted in 1903 by zoologist Robert Falcon Scott.\n\nTom: Yes, Scott was a part of a British expedition that traveled to the Antarctic and observed penguin colonies for several months. He documented the behavior of Emperor, Adelie, and Gentoo penguins and was among the first to notice their social hierarchy.\n\nJen: Since then, numerous studies have been conducted on penguin social behavior, contributing to our understanding of their complex social structures.\n\nTom: For example, one study published in the Journal of Ethology found that Adelie penguins in Antarctica had a highly structured social hierarchy that was based on proximity to food sources and shelter.\n\nJen: Another study published in the journal Behavioural Ecology and Sociobiology found that chinstrap penguins in Antarctica demonstrated a somewhat democratic social structure, with no single penguin occupying a dominant position.\n\nTom: While penguins may seem to have rigid social systems, they also have complex and fascinating personalities. One study published in the journal Animal Welfare found that penguins in captivity exhibited individual personalities, indicating that even within their social hierarchy, they demonstrate unique and individual traits.\n\nJen: And let\'s not forget about their adorable and funny behaviors. Penguins are known to "porpoise" out of the water while swimming, slide down the snow on their bellies, and even steal rocks from each other!\n\nTom: With their intricate social hierarchy, individual personalities, and unique behaviors, penguins truly are fascinating creatures that continue to intrigue scientists and animal lovers alike.\n\nJen: Thanks for listening to the CNN Podcast. Tune in next time for more interesting discussions and fun facts.'
cnn_chat.step("Long detailed episode about the social hierarchy of elephants.")2023-03-04 11:45:26 [info ] requesting openai...
2023-03-04 11:45:40 [info ] received openai...
2023-03-04 11:45:40 [info ] requesting tts i=0
2023-03-04 11:45:40 [info ] received tts i=0
2023-03-04 11:45:41 [info ] requesting tts i=1
2023-03-04 11:45:41 [info ] received tts i=1
2023-03-04 11:45:43 [info ] requesting tts i=2
2023-03-04 11:45:43 [info ] received tts i=2
2023-03-04 11:45:43 [info ] requesting tts i=3
2023-03-04 11:45:43 [info ] received tts i=3
2023-03-04 11:45:44 [info ] requesting tts i=4
2023-03-04 11:45:44 [info ] received tts i=4
2023-03-04 11:45:46 [info ] requesting tts i=5
2023-03-04 11:45:46 [info ] received tts i=5
2023-03-04 11:45:48 [info ] requesting tts i=6
2023-03-04 11:45:48 [info ] received tts i=6
2023-03-04 11:45:49 [info ] requesting tts i=7
2023-03-04 11:45:49 [info ] received tts i=7
2023-03-04 11:45:51 [info ] requesting tts i=8
2023-03-04 11:45:51 [info ] received tts i=8
2023-03-04 11:45:52 [info ] requesting tts i=9
2023-03-04 11:45:52 [info ] received tts i=9
2023-03-04 11:45:54 [info ] requesting tts i=10
2023-03-04 11:45:54 [info ] received tts i=10
2023-03-04 11:45:55 [info ] requesting tts i=11
2023-03-04 11:45:55 [info ] received tts i=11
2023-03-04 11:45:56 [info ] requesting tts i=12
2023-03-04 11:45:56 [info ] received tts i=12
2023-03-04 11:45:58 [info ] requesting tts i=13
2023-03-04 11:45:58 [info ] received tts i=13
2023-03-04 11:45:59 [info ] requesting tts i=14
2023-03-04 11:45:59 [info ] received tts i=14
2023-03-04 11:46:00 [info ] concatting audio
2023-03-04 11:46:03 [info ] done with audio!
"Tom: Welcome to the CNN Podcast, I'm Tom and I'm joined by Jen. Today we'll be discussing the social hierarchy of elephants, their complex and fascinating relationships and behaviors.\n\nJen: That's right, Tom. Elephants are highly intelligent and social animals, with a highly structured and matriarchal social hierarchy.\n\nTom: Elephants live in close-knit family units called herds, which are typically led by a dominant female elephant known as the matriarch.\n\nJen: The matriarch is responsible for leading the group and making important decisions such as where to find food and water as well as where to rest and sleep.\n\nTom: The matriarch is usually the oldest and largest female in the group, and she maintains her leadership position through a combination of strength, intelligence, and knowledge.\n\nJen: Elephants also have a system of relational ranking within their herds. This means that each individual elephant has a specific rank within the group, which is determined by their age, size, strength, and overall fitness.\n\nTom: But what's interesting is that the social hierarchy is not always rigid. Elephants can and do shift their positions within it, depending on the situation and the needs of the herd.\n\nJen: That's right, Tom. Researchers have observed cases where younger elephants have moved up in the ranks by displaying exceptional intelligence or an ability to solve problems.\n\nTom: Additionally, the matriarchal social structure doesn't just end at the individual herd level. Elephants also form larger social groups called clans, which are made up of several related herds.\n\nJen: These clans are also led by a dominant matriarch, who is usually the oldest and most experienced female in the group. And just like within a herd, individual elephants maintain their own ranks within the larger clan.\n\nTom: Elephants have a complex social structure that is not only hierarchical but also deeply empathetic. They show incredible compassion and empathy towards one another, often forming strong bonds and demonstrating a deep sense of loyalty to their family group.\n\nJen: And elephants don't just limit their compassion to their own kind. There have been numerous stories of elephants demonstrating kindness towards other species, such as rescuing stranded animals or mourning the death of other elephants as well as other animals.\n\nTom: It's of course important to mention that elephants have been known to exhibit aggressive behavior towards each other, especially during mating season or when resources are scarce.\n\nJen: Yes, that's true, Tom. But overall, elephants are gentle and empathetic creatures that have a deeply complex social structure that continues to fascinate and intrigue scientists and animal lovers alike.\n\nTom: Thanks for tuning in to the CNN Podcast. Join us next time for more interesting discussions and fun facts."
display(IPython.display.Audio(f"ht.mp3", autoplay=True))chat = Chat("Sloths", hosts=['Noa', 'Guy'])
chat.step()'[Opening music]\n\nNoa: Welcome to the show, I’m Noa.\n\nGuy: And I’m Guy. Today we’re talking about a creature that moves at a glacial pace but has captured the hearts and imaginations of people all over the world. We’re talking, of course, about…\n\nNoa and Guy (in unison): Sloths!\n\nGuy: Sloths are fascinating creatures, with their seemingly lackadaisical lifestyle and cute, often goofy faces. But there’s so much more to these animals than their outward appearance.\n\nNoa: That’s right, Guy. According to the International Union for Conservation of Nature, there are six different species of sloths, four of which are found in Central and South America.\n\nGuy: Let’s start with some history. Did you know that sloths were first documented by European explorers in the 15th and 16th centuries?\n\nNoa: Yeah, and fun fact: they were initially mistaken for monkeys. It wasn’t until the 18th century that scientists began to recognize them as a distinct group of animals.\n\nGuy: The two-toed and three-toed sloths, which are the two species that are usually mentioned, are very different from one another. In fact, they belong to separate families of the order Pilosa.\n\nNoa: Yes, and the reasons why they evolve similar adaptations to a tree-based lifestyle remain elusive.\n\nGuy: Speaking of adaptations, sloths have some pretty unique ones. For starters, they have an unusually low body temperature, which helps them conserve energy.\n\nNoa: They also have a specialized stomach that allows them to break down tough leaves, which make up the bulk of their diet.\n\nGuy: But perhaps the most notable feature of sloths is their slow metabolism. In fact, they move so slowly that they can sometimes grow algae on their fur!\n\nNoa: That’s right, Guy. But despite their slow pace, sloths are remarkable climbers. They have long claws that allow them to grip branches and leaves, and even their grip reflex is so strong that they can sometimes hold on even when they’re asleep!\n\nGuy: Sloths are being threatened by habitat loss and climate change, with some scientists labeling them as endangered. But there are signs of hope. For example, just this year, a study published in the journal “Nature Communications” showed that sloths have actually been using man-made structures such as bridges and power lines to expand their habitats!\n\nNoa: That’s amazing, Guy. Okay, now for our favorite part of the show: fun facts!\n\nGuy: Did you know that sloths only need to poop once a week?\n\nNoa: What? How is that even possible?\n\nGuy: They have very slow metabolisms, remember? And it turns out that going more than a week without pooping is actually not uncommon for sloths. In fact, there’s a theory that they only defecate on the ground because moths lay their eggs in their poop, which in turn provides a food source for the sloths.\n\nNoa: Wow, that’s wild. Here’s another one: the hair on sloths’ stomachs grows in the opposite direction from the hair on the rest of their body. This helps to keep their internal organs warm, as their body temperature is usually lower than that of other mammals.\n\nGuy: Speaking of hair, sloths’ fur is so thick and luxurious that it’s been used to make blankets and even beds!\n\nNoa: And one last fact before we sign off: sloths may be slow, but they’re not lazy. In fact, a study in the journal “Current Biology” showed that they spend up to 90% of their time resting, but the remainder is spent moving around and foraging for food.\n\nGuy: Well, that’s it for today’s show. We hope you’ve enjoyed learning about sloths as much as we have. Don’t forget to tune in next week for another fascinating topic!\n\n[Closing music]'
chat.step('Make another funny episode about Sloths. Do not repeat any information from before.')'[Opening music]\n\nNoa: Welcome to the show, I’m Noa.\n\nGuy: And I’m Guy. Today, we’re talking about the laziest, sleepiest, and cutest animals on the planet: sloths!\n\nNoa: Speaking of laziness, did you know that sloths sleep for up to 15 hours a day? That’s nearly two-thirds of their entire life!\n\nGuy: Don’t forget about their slow movement. Sloths move so slowly that scientists once clocked one traveling just seven feet in a minute.\n\nNoa: And did you know that sloths have a symbiotic relationship with moths? Sloths grow algae on their fur, which the moths then eat.\n\nGuy: Wait, what? Algae? On their fur? That’s disgusting!\n\nNoa: Hey, don’t be sloth-shaming. Besides, if you think that’s gross, just wait until you hear about the sloth’s digestive system.\n\nGuy: I don’t think I want to hear this.\n\nNoa: Sloths only poop once a week, and it can take them up to a month to digest one meal.\n\nGuy: Ew, that’s seriously gross.\n\nNoa: Hey, you’re the one who wanted to talk about sloths.\n\nGuy: Touché. But let’s talk about something more wholesome. Did you know that sloth babies are called “slothies”?\n\nNoa: Aww, that’s adorable. And you know what’s even cuter? Sloths in onesies.\n\nGuy: Wait, what? Sloths in onesies?\n\nNoa: Yes, there’s actually a company that makes onesies that look like sloths. They’re so cute, you’ll want one for yourself!\n\nGuy: Alright, I’ve got to admit, that’s pretty cute. But back to the real sloths. Did you know that their long claws can make it difficult for them to walk on the ground?\n\nNoa: Yes, it’s like they’re wearing high heels all the time.\n\nGuy: And speaking of their claws, they only have two or three of them on their front feet, depending on the species.\n\nNoa: I guess sloths never need to clip their nails.\n\nGuy: And finally, did you know that there are even some sloths that live in the water?\n\nNoa: Seriously? I guess they’re not the only ones who like to take it slow.\n\nGuy: And on that note, we’ll end today’s show. We hope you got a good laugh out of our sloth-filled episode. Tune in next time for another wild and wacky topic!\n\n[Closing music]'
msg = chat.message('Tell me other things about yogurt and make it funny')
Chat.text2speech(msg)chat._history[{'role': 'system',
'content': 'You are an award winning NPR podcast with hosts Tom and Jen.'},
{'role': 'user',
'content': 'Generate a podcast episode about Yogurt, including history and other fun facts. Reference published scientific journals.'},
{'role': 'assistant',
'content': 'Tom: Welcome back to our podcast, today we are discussing Yogurt! A dairy product that has been around for thousands of years.\n\nJen: That’s right, Tom. In fact, the origins of yogurt can be traced back to the Neolithic period over 10,000 years ago. Nomadic tribes in Central Asia discovered that milk left to ferment in animal skins preserved the milk and created a tasty and nutritious sour milk product, which we now know as yogurt.\n\nTom: That’s fascinating. I had no idea yogurt had such a rich history. What are some of the health benefits of eating yogurt?\n\nJen: Well, according to research published in the American Journal of Clinical Nutrition, yogurt is a great source of calcium, protein, and other essential nutrients. Additionally, the live and active cultures found in yogurt can help support a healthy digestive system by providing beneficial bacteria to the gut.\n\nTom: That’s good to know. Is all yogurt created equal?\n\nJen: Not necessarily. It’s important to check the labels of yogurts to ensure they contain live and active cultures, which are the beneficial bacteria that support gut health. Some yogurts may also contain added sugars or artificial ingredients, so it’s important to choose a yogurt that is minimally processed and contains natural ingredients.\n\nTom: I see, thanks for that information. Are there any other fun facts about yogurt that you’d like to share?\n\nJen: Sure, did you know that yogurt can be made from a variety of animal milks, including cow, goat, and sheep milk? Additionally, some types of yogurt are strained multiple times to create a thicker consistency, such as Greek yogurt.\n\nTom: Wow, the more you know! Thanks for joining us today on our podcast. We hope you learned something new and will continue to tune in for future episodes.'},
{'role': 'user',
'content': 'Tell me other things about yogurt and make it funny'},
{'role': 'assistant',
'content': 'Tom: Let\'s dive into some more interesting facts about yogurt! Did you know that the word \'yogurt\' comes from a Turkish word that means \'to thicken\'? That\'s quite fitting, as yogurt is known for its thick, creamy texture.\n\nJen: And did you know that yogurt was once used as a beauty treatment? In ancient India, yogurt was believed to have skin-rejuvenating properties and was applied to the face as a facial mask.\n\nTom: I guess you could say that yogurt is not only good for your gut but also good for your complexion! *laughs*\n\nJen: Speaking of yogurt, there are so many different flavors out there now. You can even get yogurt that tastes like your favorite desserts, such as key lime pie or strawberry cheesecake.\n\nTom: Yes, it\'s amazing how far yogurt has come from its humble beginnings as a sour, fermented milk product. I mean, who would have thought that one day we\'d be eating yogurt that tastes like a slice of cherry pie?\n\nJen: And let\'s not forget about the famous yogurt-eating scene in the movie \'The Matrix\' where Morpheus offers Neo a choice between the red pill and the blue pill, saying "You take the blue pill, the story ends. You wake up in your bed and believe whatever you want to believe. You take the red pill, you stay in Wonderland, and I show you how deep the rabbit hole goes." And then he offers him some yogurt as if it\'s some kind of mind-altering substance.\n\nTom: *laughs* Yeah, that was definitely a moment in cinematic history. But in all seriousness, yogurt is a delicious and healthy food that has been enjoyed for thousands of years. So, go ahead and indulge in some yogurt, whether it\'s plain or flavored, and see all the benefits it has to offer!'}]
"""
TODO:
Make web server and send mp3 to frontend
Make frontend and play results
"""'\nTODO:\n'